From bdba1b19a23179ba4dec3fbc10860deaf072214c Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Fri, 21 Apr 2023 09:51:54 -0600 Subject: [PATCH] keep gdb route point names and waypoint names aligned. (#1075) This used to work in 1.4.4, but stopped working with the conversion to QString (NEW_STRINGS). Add a test case to verify the names match. --- gdb.cc | 20 ++++++++------------ reference/route/gdbroutenametest.csv | 6 ++++++ reference/route/gdbroutenametest~csv.csv | 5 +++++ testo.d/gdb.test | 10 ++++++++++ 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 reference/route/gdbroutenametest.csv create mode 100644 reference/route/gdbroutenametest~csv.csv diff --git a/gdb.cc b/gdb.cc index 7ba6bd6ca..23c77a02e 100644 --- a/gdb.cc +++ b/gdb.cc @@ -88,12 +88,9 @@ GdbFormat::gdb_flush_waypt_queue(QList* Q) while (!Q->isEmpty()) { const Waypoint* wpt = Q->takeFirst(); if (wpt->extra_data) { - // FIXME // wpt->extra_data may be holding a pointer to a QString, courtesy - // the grossness at the end of write_waypt_cb(). If that leaks, - // (and I think it will) find some way to do the approximate equivalent - // of: - // delete static_cast(wpt->extra_data); + // the grossness at the end of write_waypoint_cb(). + delete static_cast(wpt->extra_data); } delete wpt; } @@ -256,12 +253,10 @@ GdbFormat::gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_cla RAD(tmp->latitude), RAD(tmp->longitude))); if (fabs(dist) > 100) { - warning(MYNAME ": Route point mismatch!\n"); - warning(MYNAME ": \"%s\" from waypoints differs to \"%s\"\n", - qPrintable(tmp->shortname), qPrintable(ref->shortname)); - fatal(MYNAME ": from route table by more than %0.1f meters!\n", - dist); - + fatal(MYNAME ": Route point mismatch!\n" \ + " \"%s\" from waypoints differs to \"%s\"\n" \ + " from route table by more than %0.1f meters!\n", \ + qPrintable(tmp->shortname), qPrintable(ref->shortname), dist); } } Waypoint* res = nullptr; @@ -1436,7 +1431,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name) garmin_fs_t* gmsd = garmin_fs_t::find(wpt); /* extra_data may contain a modified shortname */ - FWRITE_CSTR((wpt->extra_data) ? (char*)wpt->extra_data : wpt->shortname); + FWRITE_CSTR((wpt->extra_data) ? *static_cast(wpt->extra_data) : wpt->shortname); int wpt_class = wpt->wpt_flags.fmt_use; /* trick */ @@ -1655,6 +1650,7 @@ GdbFormat::write_waypoint_cb(const Waypoint* refpt) } name = mkshort(short_h, name); + wpt->extra_data = new QString(name); write_waypoint(wpt, name, gmsd, icon, display); finalize_item(fsave, 'W'); diff --git a/reference/route/gdbroutenametest.csv b/reference/route/gdbroutenametest.csv new file mode 100644 index 000000000..929a7c38f --- /dev/null +++ b/reference/route/gdbroutenametest.csv @@ -0,0 +1,6 @@ +name,lat,lon +RoutePoint,40.00,-105.00 +RoutePoint,40.01,-105.00 +RoutePoint,40.01,-105.01 +RoutePoint,40.02,-105.01 + diff --git a/reference/route/gdbroutenametest~csv.csv b/reference/route/gdbroutenametest~csv.csv new file mode 100644 index 000000000..76e8f89a4 --- /dev/null +++ b/reference/route/gdbroutenametest~csv.csv @@ -0,0 +1,5 @@ +No,Latitude,Longitude,Name,Symbol +1,40.000000,-105.000000,"RoutePoint","Waypoint" +2,40.010000,-105.000000,"RoutePoint.1","Waypoint" +3,40.010000,-105.010000,"RoutePoint.2","Waypoint" +4,40.020000,-105.010000,"RoutePoint.3","Waypoint" diff --git a/testo.d/gdb.test b/testo.d/gdb.test index dc8f003e5..390d0b938 100644 --- a/testo.d/gdb.test +++ b/testo.d/gdb.test @@ -29,3 +29,13 @@ compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample_v3.gpx # don't choke if autoroute information is present. gpsbabel -i gdb,dropwpt -f ${REFERENCE}/gdb-sample-v3-autoroute.gdb -o gpx -F ${TMPDIR}/gdb-sample-v3-autoroute.gpx compare ${REFERENCE}/gdb-sample-v3-autoroute.gpx ${TMPDIR}/gdb-sample-v3-autoroute.gpx + +# test that the Route point Point names from the 'R' records match the Waypoint names from the 'W' records. +# the names in the csv input are all identical which forces the gdb writer to uniquify them. +gpsbabel -r -i unicsv -f ${REFERENCE}/route/gdbroutenametest.csv -o gdb -F ${TMPDIR}/gdbroutenametest.gdb +# if we don't match the names we will get a fatal error: +# gdb: Route point mismatch! +# "RoutePoint" from waypoints differs to "RoutePoint" +# from route table by more than 1113.2 meters! +gpsbabel -r -i gdb -f ${TMPDIR}/gdbroutenametest.gdb -o unicsv -F ${TMPDIR}/gdbroutenametest.csv +compare ${REFERENCE}/route/gdbroutenametest~csv.csv ${TMPDIR}/gdbroutenametest.csv -- 2.30.2